October 13, 2022

Roadmap

Roadmap

  • Writing philosophy
  • What is R Markdown?
  • Why use R Markdown?
  • R Markdown Basics
    • Installation
    • Text
    • Code
    • References and Bibliographies
  • Wrap up

Philosophy

What is writing?

What is writing?

What is writing?

What is writing?

Really, all three. Software-wise, this translates into two main schools:

  • WYSIWYG–What You See Is What You Get: word processing software, e.g., Microsoft Word1

  • WISIWIT–What I See Is What I Type: typesetting software, e.g., LaTeX1

What is R Markdown?

R Markdown is a file format for making dynamic documents with R. Kind of half-way between Word and LaTeX.

An R Markdown document is written in markdown and contains text, code, and output.

Ok, what’s markdown?

Markdown is a plain text formatting syntax2: you can read markdown in its source format and still understand it, like this:

Hello, Lab! Y'all still with me?

Why use R Markdown?

Why use R Markdown?

Practical reasons

  • You already know 50% of the language!
  • Transferable and Versatile
  • Work smarter, not harder
    • Code comments
    • Code rationale
    • Stats interpretation
  • Free, Open Source

Philosophical reasons

  • WISIWIT >> WYSIWYG (?)
  • Transparent
  • Shorter workflow
    • less software involved
  • Open Science
  • Free, Open Source

Why use R Markdown?

R Markdown Basics

Installation

If you installed RStudio, congrats! You’re all set to start using R Markdown.

If you prefer to not use RStudio, make sure to install the rmarkdown package.

In either case, make sure to install the tinytex package, which will let you export your work as PDF (sometimes required, i.e., most papers’ Supplementary Information.

The R Markdown formula

Text

Writing text in markdown is easy: just type. You can type formatting too!

*italics* or _italics_

**bold**

sub~script~

super^script^

italics

bold

subscript

superscript

If you need headers, mark them with #. The more # in front of some text, the lower the header’s level.

More text formatting here, and we’ll see some in action in just a few.

Code

Right, now to the real deal. Markdown lets you seamlessly switch from writing plain old text to code.

What kind of code? R, obviously, but also Python, Bash, SQL,…

Of course, you got to tell R that you’re about to write some magic text, or it will just spin…

Code

Code in R markdown can be written inline.

For instance this ` r format(Sys.Date(), "%A, %B %d, %Y") ` produces this Thursday, October 13, 2022.

Use ` to signal the start and the end of a piece of inline code.

Code can also take up a portion of the document—i.e., a chunk. To open and close a code chunk, use ```. Always close code chunks!

Code

Code chunks can contain any piece of code you want, provided you load the appropriate packages and correctly set your working directory.

setwd("/Users/matteo/rmarkdowntour/")

library(tidyverse)
library(knitr)

Don’t mess up, be a

Output

The standard R Markdown output is an HTML file. R uses pandoc to read R Markdown and blurt out a fancy-looking thing.

What’s pandoc, then?

pandoc is the universal document converter. It’s a tiny piece of open source software that can convert almost any document format into any other format. Don’t worry, you don’t need to install anything more!

The output looks beautiful, like the presentation you’re looking at ;)

Alright,

Wrapping it up

R Markdown: from Data Collection to Paper

Wrapping it up

I hope I’ve convinced you to at least try R Markdown out.

What I’ve shown you if all you need (I think…) to start working in R Markdown and produce reports and Supplementary Information for your analyses.

You can do a lot more than the simple stuff I showed you today. For instance, interactive graphs, maps, tables, websites, presentations, etc.

If you do, consider learning about git and version control. They’ll make your life so much easier! But that’s another lab meeting…

Wrapping it up

Important! Research shows that coding with music is 100% more enjoyable. It also helps a lot to cover your screams of rage when R Markdown will give you the (inevitable) middle finger. So, always remember to

Some Useful Resources

Thank you!